package com.test.demo.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.test.demo.R;
import com.test.demo.main.bean.MediumBean;

import java.util.List;


public class ViewPagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final static String TAG = "RecyclerBaseAdapter";

    private List<MediumBean> itemDataList = null;
    private Context context = null;

    public ViewPagerAdapter(Context context, List<MediumBean> itemDataList) {
        this.itemDataList = itemDataList;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
                                                      int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.item_browse_image, parent, false);
        final RecyclerView.ViewHolder holder = new RecyclerItemImageHolder(context, v);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof RecyclerItemImageHolder) {
            RecyclerItemImageHolder recyclerItemViewHolder = (RecyclerItemImageHolder) holder;
            recyclerItemViewHolder.setRecyclerBaseAdapter(this);
            recyclerItemViewHolder.onBind(position, itemDataList.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return itemDataList.size();
    }


    @Override
    public int getItemViewType(int position) {
        return itemDataList.get(position).getType();
    }

    public void setListData(List<MediumBean> data) {
        itemDataList = data;
        notifyDataSetChanged();
    }
}
